package com.ma.entity;

import com.google.protobuf.AbstractMessage.Builder;
import com.google.protobuf.Descriptors;
import com.ma.test.protobuf.Login.loginmsg;
import com.ma.test.protobuf.nulldata;
import com.ma.test.protobuf.testmsg;

public class ProtobufBuilder {

	private static Descriptors.FieldDescriptor getField(Descriptors.Descriptor descriptor, String name) {
	return descriptor.findFieldByName(name);
}
	public static byte[] loginmsgBuilder(String loginname,String password,long id,String creatdate) {
		Builder b = loginmsg.newBuilder();
		b.setField(getField(b.getDescriptorForType(), "loginname"), loginname);
		b.setField(getField(b.getDescriptorForType(), "password"), password);
		b.setField(getField(b.getDescriptorForType(), "id"), id);
		b.setField(getField(b.getDescriptorForType(), "creatdate"), creatdate);
		return b.build().toByteArray();
	}
	
	public static byte[] stringmsgBuilder(String msg) {
		Builder b = testmsg.newBuilder();
		b.setField(getField(b.getDescriptorForType(), "message"), msg);
		return b.build().toByteArray();
	}
	public static byte[] nulldataBuilder() {
		Builder b = nulldata.newBuilder();
		return  b.build().toByteArray();
	}
}
